//package com.zhentao.filter;
//
//import com.zhentao.util.AppJwtUtil;
//import io.jsonwebtoken.Claims;
//import org.apache.commons.lang.StringUtils;
//import org.springframework.cloud.gateway.filter.GatewayFilterChain;
//import org.springframework.cloud.gateway.filter.GlobalFilter;
//import org.springframework.core.Ordered;
//import org.springframework.http.HttpStatus;
//import org.springframework.http.server.reactive.ServerHttpRequest;
//import org.springframework.http.server.reactive.ServerHttpResponse;
//import org.springframework.stereotype.Component;
//import org.springframework.web.server.ServerWebExchange;
//import reactor.core.publisher.Mono;
//
//import java.util.ArrayList;
//import java.util.List;
//
//@Component
//public class AuthorizeFilter implements GlobalFilter, Ordered {
//
////    // 匿名可访问的 url，网关过滤器其他代码省略
////    private static final List<String> ANONYMOUS_URI_LIST = new ArrayList<>();
////
////    static {
////        // 注意：生产环境下面这两个要注释掉，或者用开启停用状态来确保接口文档是否可匿名访问。
////        ANONYMOUS_URI_LIST.add("/doc.html");
////        ANONYMOUS_URI_LIST.add("/v2/api-docs");
//////        ANONYMOUS_URI_LIST.add("/user/login");
////    }
//
//    @Override
//    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
//        //获取request、response
//        ServerHttpRequest request = exchange.getRequest();
//        ServerHttpResponse response = exchange.getResponse();
//
//
////        判断是否是登录
//        if (request.getURI().getPath().contains("/system/index") ) {
//            return chain.filter(exchange);
//        }
//
//        String token = request.getHeaders().getFirst("VEA-TOKEN");
//
////        判断token是否存在
//        if (StringUtils.isBlank(token)) {
//            response.setStatusCode(HttpStatus.UNAUTHORIZED);
//            return response.setComplete();
//        }
//
////        判断token是否有效
//        try {
//            Claims claimsBody = AppJwtUtil.getClaimsBody(token);
////            判断是否过期
//            int verifyToken = AppJwtUtil.verifyToken(claimsBody);
//            if (verifyToken == 1 || verifyToken == 2) {
//                response.setStatusCode(HttpStatus.UNAUTHORIZED);
//                return response.setComplete();
//            }
//
//        } catch (Exception e) {
//            e.printStackTrace();
//            response.setStatusCode(HttpStatus.UNAUTHORIZED);
//            return response.setComplete();
//        }
//
////        放行
//        return chain.filter(exchange);
//    }
//
//    @Override
//    public int getOrder() {
//        return 0;
//    }
//}
